package com.zt.bigdata.spark.elasticsearch

import org.apache.spark.SparkContext
import org.elasticsearch.spark._
/**
  * @ClassName SparkEs
  * @Description
  * @Author zhangtonghy
  * @Date 2019-04-18 16:51
  * @Copyright: 版权所有 (C) zt zt.
  * @注意 ：本内容仅限于zt内部传阅，禁止外泄以及用于其他的商业目的
  **/

object SparkEs {
  def main(args: Array[String]): Unit = {
    import org.apache.spark.SparkConf
    val conf = new SparkConf().setAppName("sparkES").setMaster("local[2]")
    conf.set("es.index.auto.create", "true")
    conf.set("es.nodes","172.28.23.35")
    conf.set("es.port","9200")
    conf.set("es.net.http.auth.user","elastic")
    conf.set("es.net.http.auth.pass","elastic")

    val numbers = Map("one" -> 1, "two" -> 2, "three" -> 3)
    val airports = Map("arrival" -> "Otopeni", "SFO" -> "San Fran")
    val spark = new SparkContext(conf)

    spark.makeRDD(
      Seq(numbers, airports)
    ).saveToEs("spark/docs")
  }
}
